home *** CD-ROM | disk | FTP | other *** search
/ Night Owl 6 / Night Owl's Shareware - PDSI-006 - Night Owl Corp (1990).iso / 020a / rmastr02.zip / RWDEF.PAS < prev    next >
Pascal/Delphi Source File  |  1991-09-25  |  2KB  |  70 lines

  1. Unit RWDef;
  2.  
  3. Interface
  4.  
  5.  Procedure ReadDef(Filename : String; X,Y : Word);
  6.  Procedure WriteDef(Filename    : String; X1,Y1,X2,Y2 : Word);
  7.  
  8. Implementation
  9.     Uses Graph;
  10.  
  11.  Procedure ReadDef(Filename : String; X,Y : Word);
  12.  Var
  13.   F  : Text;
  14.   Ch : Char;
  15.   Col: Word;
  16.   SX : Word;
  17.  Begin
  18.    SX:=X;
  19.    Assign(F,Filename);
  20.    Reset(F);
  21.    Repeat
  22.      Ch:=' ';
  23.      Repeat
  24.       Read(F,Ch);                                  (*Read a character *)
  25.       Col:=0;
  26.       Case Ord(Ch) of 48..57:Begin
  27.                               Col:=Ord(Ch)-48;     (*Convert Hex character to*)
  28.                               PutPixel(SX,Y,Col);  (*number. From 0 to 9 *)
  29.                              End;
  30.                       65..70:Begin
  31.                               Col:=Ord(Ch)-55;     (*Convert Hex character to*)
  32.                               PutPixel(SX,Y,Col);  (*number. From 10 to 15 *)
  33.                              End;
  34.  
  35.       End;
  36.       Inc(SX);
  37.      Until Ch=chr(13);  (*Keep repeating the loop until we hit a carriage return*)
  38.      Read(F,Ch);        (*This character should be a line feed, we just read it*)
  39.      Inc(Y);            (*Increase Y by 1*)
  40.      SX:=X;             (*Set SX to X*)
  41.    Until Eof(F);        (*Keep repeating until we reach the end of the file*)
  42.    Close(F);
  43.  End;
  44.  
  45.  Procedure WriteDef(Filename    : String; X1,Y1,X2,Y2 : Word);
  46.  Const
  47.   Hex : array[0..15] of char = ('0','1','2','3','4','5','6','7','8','9',
  48.                                 'A','B','C','D','E','F');
  49.  Var
  50.   F   : Text;
  51.   I   : Word;
  52.   J   : Word;
  53.   Col : Word;
  54.  Begin
  55.   Assign(F,Filename);
  56.   Rewrite(F);
  57.   For J:=Y1 to Y2 do
  58.   Begin
  59.    For I:=X1 to X2 do
  60.    begin
  61.      Col:=GetPixel(I,J);
  62.      Write(F,Hex[Col]);
  63.    End;
  64.    Writeln(F);
  65.   End;
  66.   Close(F);
  67.  End;
  68.  
  69. Begin
  70. End.